package com.lanou3g;

import java.io.*;
import java.util.Random;

/**
 * Created by dllo on 18/4/20.
 */
public class Main {

    //目标是1G
    public static final long TARGET = 1024 *1024*1024;
    public static void main(String[] args) {


        new Thread(){
            @Override
            public void run() {
                creatFile("a","/Users/dllo/Desktop/hw/作业/Q2");
            }
        }.start();

        //主线程的必须写在子线程的下面，保证同时进行
        creatFile("b","/Users/dllo/Desktop/hw/作业/Q2");


    }
    private static void creatFile(String fileName,String filePath){
        File file = new File(filePath,fileName); //文件夹：文件名
        BufferedOutputStream bos = null;
        try {
            bos = new BufferedOutputStream(new FileOutputStream(file));

          //  Random random = new Random();
            byte[] buf = new byte[1024];
           // random.nextBytes(buf); 转成随机的
            long sum = 0;
            while (sum < TARGET ){
                bos.write(buf);
                sum += 1024L;
            }

            bos.flush();

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (bos != null){
                try {
                    bos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }
}
